package zhuyun.code.launcheractivity.view.adapter

import android.util.SparseIntArray
import android.view.ViewGroup
import zhuyun.code.launcheractivity.view.interfaces.MultiItemEntity

/**
 * @author: Administrator
 * @date: 2021/12/4
 */
abstract class BaseMultiItemQuickAdapter<T: MultiItemEntity,K: BaseViewHolder>(private val data:MutableList<T>):BaseQuickAdapter<T,K>(0,data) {
    override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): K {
        return createBaseViewHolder(parent,getLayoutId(viewType))
    }
    private val layouts by lazy { SparseIntArray() }

    private fun getLayoutId(viewType:Int):Int{
        return layouts.get(viewType)
    }

    protected fun addItemType(type:Int, layoutResId:Int){
        layouts.put(type,layoutResId)
    }

    override fun getItemViewType(position: Int): Int {
        return data[position].getItemType()
    }

}